namespace :mrm do
  namespace :test do
    desc "Copy mysql routines from dev to test. Pass test database name in \
form of TEST_DB=test_database_name if your databases have unconventional names."
    task :clone_routines => :environment do
      unless ENV['TEST_DB']
        test_db = ActiveRecord::Base.connection.current_database.sub('dev','test')
      else
        test_db = ENV['TEST_DB']
      end
      MysqlRoutine.delete_all("db = '#{test_db}'")
      
      routines = MysqlRoutine.find(:all)
      
      routines.each do |dev_routine|
        MysqlRoutine.create!(dev_routine.attributes.merge({:db => test_db}))
      end
    end
  end
end